import axios from 'axios'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const onlineUrl = 'https://lianghj.top:8888/api/private/v1/'

const request = axios.create({
  // baseURL: 'http://127.0.0.1:8888/api/private/v1/'
  baseURL: onlineUrl
})

// 基于拦截器展示进度条和隐藏进度条

// 1.设置axios请求拦截器
request.interceptors.request.use(config => {
  NProgress.start()
  if (config.url !== 'login') {
    config.headers.Authorization = sessionStorage.getItem('token')
  }
  return config
}, error => {
  return Promise.reject(error)
})

// 2..设置axios响应拦截器
request.interceptors.response.use(config => {
  NProgress.done()
  return config
})

export default request
